package interview;

/**
 * @author zhangjie
 */
public class BinarySearchDif {

  public static void main(String[] args) {
    System.out.println(solution("abcdefg", "acdefg"));
  }

  public static int solution(String s1, String s2) {
    //abcdefg
    //acdefg
    int left = 0;
    int right = Math.min(s1.length(), s2.length()) - 1;
    while (left <= right) {
      int mid = left + ((right - left) >>> 1);
      if (s1.charAt(mid) == s2.charAt(mid)) {
        left = mid + 1;
      } else if (s1.charAt(mid - 1) == s2.charAt(mid - 1)) {
        return mid;
      } else {
        right = mid - 1;
      }
    }

    return -1;


  }
}
